class Solution:
    def generateParenthesis(self, n: int):
        b=[]
        c=[]
        def a(m, l, r):
            if m == n*2:
                c.append("".join(b))
            else:
                if l < n:
                    b.append("(")
                    a(m + 1, l+1, r)
                    b.pop()
                if l > r:
                    b.append(")")
                    a(m+1, l, r+1)
                    b.pop()
        a(0, 0, 0)
        return c
